package cn.chen.utils;

import cn.chen.utils.bean.ValueEnum;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

public class HelperUtils {

    public static <T, R> List<R> convertVO(List<T> list, Function<T, R> converter) {
        if (list == null || list.isEmpty()) {
            return Collections.emptyList();
        }
        return list.stream().map(converter).collect(Collectors.toList());
    }

    public static <E extends Enum<E> & ValueEnum<T>, T> E convertEnum(Class<E> enumClass, T value) {
        return Arrays.stream(enumClass.getEnumConstants())
                .filter(e -> Objects.equals(e.getValue(), value))
                .findFirst()
                .orElse(null);
    }
}
